using System.Collections.Generic;
using Godot;

class SceneUtil
{
    /// <summary>
    /// 根据id返回场景路径
    /// </summary>
    /// <param name="id"> 场景id</param>
    /// <returns>场景路径</returns>
    public static string getScenePath(SceneId id)
    {
        List<ConfigScene> sceneConfig = ConfigManager.getInstance().findAllConfig<ConfigScene>("ConfigScene");
        foreach (var config in sceneConfig)
        {
            if (config.ID == (int)id && config.ID != (int)SceneId.allScene)
            {
                return "res://scene/" + config.fileName + ".tscn";
            }
        }
        return null;
    }

    public static ConfigScene GetSceneConfig(SceneId id)
    {
        List<ConfigScene> sceneConfig = ConfigManager.getInstance().findAllConfig<ConfigScene>("ConfigScene");
        foreach (var config in sceneConfig)
        {
            if (config.ID == (int)id && config.ID != (int)SceneId.allScene)
            {
                return config;
            }
        }
        return null;
    }
    public static SceneBase currentScene { get; set; }

    public static Node sceneRootNode { get; set; }  //游戏启动的时候设置

    public static void ChangeScene(SceneBase scene)
    {
        sceneRootNode.RemoveChild(currentScene);
        sceneRootNode.AddChild(scene);
        currentScene.Free();
        scene.EnterScene();  //初始化信息
        currentScene = scene;
    }
}